package com.example.uidemo_01.Test;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.example.uidemo_01.R;
import com.example.uidemo_01.util.ToastUtil;

public class SlideActivity extends AppCompatActivity {
    //声明控件
    private ImageView mIvHead;
    private SlideMenu slideMenu;
    private Button mBtnStudy;
    private Button mBtnPlay;
    private Button mBtnExercises;
    private Button mBtnRead;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide);

        //找到控件
        mIvHead = findViewById(R.id.iv_head);
        slideMenu = findViewById(R.id.slideMenu);
        mBtnStudy = findViewById(R.id.btn_main_1);
        mBtnPlay = findViewById(R.id.btn_main_2);
        mBtnExercises = findViewById(R.id.btn_main_3);
        mBtnRead = findViewById(R.id.btn_main_4);

        //实现侧滑的部分,点击加侧滑
        mIvHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                slideMenu.switchMenu();
                ToastUtil.showMsg(SlideActivity.this,"ok");
            }
        });
        setListener();
    }

    private void setListener(){
        Onclick onclick = new Onclick();

        //对每一个按钮进行setOnClickListener
        mBtnStudy.setOnClickListener(onclick);
        mBtnPlay.setOnClickListener(onclick);
        mBtnExercises.setOnClickListener(onclick);
        mBtnRead.setOnClickListener(onclick);
    }

    private class Onclick implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()){
                case R.id.btn_main_1:
                    intent = new Intent(SlideActivity.this,StudyActivity.class);
                    break;
                case R.id.btn_main_2:
                    intent = new Intent(SlideActivity.this,PlayActivity.class);
                    break;
                case R.id.btn_main_3:
                    intent = new Intent(SlideActivity.this,ExercisesActivity.class);
                    break;
                case R.id.btn_main_4:
                    intent = new Intent(SlideActivity.this,ReadActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }

}
